const BASE = window.__POWERED_BY_QIANKUN__ ? "/nuxt" : "";

function dynamicImport(path) {
    return import(`~/views/${path}/index.vue`).then(m => m.default || m);
}

const resolveRoute = route => ({
    ...route,
    component: () => dynamicImport(route.component)
});

function dynamicImportRoute(routes) {
    return routes.map(route => ({
        ...resolveRoute(route),
        children: route.children ? route.children.map(resolveRoute) : []
    }));
}

let routes = [
    {
        path: `/`,
        name: "Home",
        component: "home",
        alias: `${BASE}`
    },
    {
        path: `/about`,
        name: "About",
        component: "about"
    },
    {
        path: `/test`,
        name: "Test",
        component: "test"
    }
];

export default dynamicImportRoute(routes);
